package org.example.entity;

import java.util.Collection;
import java.util.Set;
import javax.persistence.Basic;
import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.CacheConcurrencyStrategy;


@Entity
@Table(name="user")
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class UserModel extends AbstractCodeModel
{
  private String password;
  private String username;
  private Collection<DataModel> data;
  private Set<GroupModel> groups;


  public UserModel()
  {
    super();
    // TODO Auto-generated constructor stub
  }

  @Basic(optional = true)
  @Column(nullable = true, name = "password")
  public String getPassword()
  {
    return password;
  }


  public void setPassword(String password)
  {
    this.password = password;
  }


  @Basic(optional = true)
  @Column(nullable = true, name = "username")
  public String getUsername()
  {
    return username;
  }


  public void setUsername(String username)
  {
    this.username = username;
  }

  @OneToMany(mappedBy="owner")
  public Collection<DataModel> getData()
  {
    return data;
  }


  public void setData(Collection<DataModel> data)
  {
    this.data = data;
  }

  @ManyToMany
  @JoinTable(name = "user_group",
             joinColumns =
             @JoinColumn(name="group_id", referencedColumnName="id"),
             inverseJoinColumns =
             @JoinColumn(name="user_id", referencedColumnName="id"))
  public Set<GroupModel> getGroups()
  {
    return groups;
  }

  public void setGroups(Set<GroupModel> groups)
  {
    this.groups = groups;
  }


}
